<?php
    /**
    * @author yzs1013@163.com
    * filename zqnews.class.php
    */


    require_once(APP_PATH . "Common/yzs1013_pldr.php");


    class Zqnews
    {
        public $url="";
        public $nr="";
        public $jj="";
        public $pic="";
        public $secexe=0;
        public $rs;
        public $nextpagere;
        public $nextpagerem;
        public $bug;
        public $bg2312;
        public $swfstr="";
        public $tempnr;
        public $ytempnr;
        public $yuannr;
        protected $parentpath="";
        public $charset;
        public $gather_type;

        public function Zqnews($url, $tempnr = '',$bug=0,$gather_type=1){
            $this->url=$url;
            $rs=$this->getrs();
            $this->gather_type=$gather_type;
            if(preg_match("/bug=([0-9]+)|375w3/isx",$url,$nn)){
                if($nn[1]=="") $nn[1]=2;
                $this->bug=$nn[1];
            }

            if($tempnr==""){
                $tempnr=self::getTempnr($gather_type);//抓取分页或内容为空时，抓取页面内容
                //echo "获取内容结束:".js();
            }

            $this->yuannr=$tempnr;
            $tempnr=dquanurl($tempnr,$url);
            $this->ytempnr=$tempnr;
            //if($this->bug==2){$fn=fopen("d:/temp0.txt","w");fwrite($fn,$this->url."\r\n".$tempnr);fclose($fn);}
            $tempnr=preg_replace("/(desc|alt)=\"(.*)\"/Uisxe",'"\\1=\"".strip_tags3("\\2")."\""',$tempnr);
            $tempnr=preg_replace("/<(?!img)([a-z]+)\s*[^<>]*>(<(?!img)[^<>]*>|\s)*<\/\\1>/Uisx","",$tempnr);

            if($this->bug==1){
                echo $tempnr;
            }


            if($rs['pre_delete']!=""){
                $dd=explode("|||",$rs['pre_delete']);
                foreach($dd as $one){
                    $one = trim($one);
                    $one=(!isutf8($one))?u($one):$one;
                    if(trim($one)=="") continue;
                    if(preg_match("/".trim($one)."/Uisx",$tempnr)){
                        $tempnr=preg_replace("/".trim($one)."/Uisx","",$tempnr);
                        $this->ytempnr=preg_replace("/".trim($one)."/Uisx","",$this->ytempnr);    
                    }
                }
            }

            $tempnr=preg_replace("/\s(alt|title|style|border)=\"[^<>\"]+\"/Uisx","",$tempnr);

            //if($this->bug==2){$fn=fopen("d:/temp.txt","w");fwrite($fn,$this->url."\r\n".$tempnr);fclose($fn);exit;}    
            //echo $tempnr;exit;
            $tempnr=preg_replace("/border=[0-9]+/isx","",$tempnr);

            $tempnr=preg_replace("/<(span|font)\s+[^<>]*(display\:none|class=\"jammer\")[^<>]*>[^<>]*<\/(span|font)>/Uisx","",$tempnr);    

            $tempnr=preg_replace("/<div[^<>]*>(?:\s*<div[^<>]*>)?(<\/?(a|span|p|br)[^<>]*>|\s|\&nbsp\;)*(<img[^<>]*>)(<"."?\/?(a|span|p|br)[^<>]*>|([^\<\>a-z0-9_\s]|\&nbsp\;|\s))*<\/div>(\s*<\/div>)??/Uisx","\\3\\4",$tempnr);

            swf_replace($this->yuannr,$this->url,$swfstr,host($this->url));//
            $this->swfstr=$swfstr;

            if($this->bug==1){
                echo "\r\nfirst replace-----------------------\r\n".$tempnr."\r\nend first replace--------------------";
            }


            $this->tempnr=$this->nr=$tempnr;
            return $this->nr;
        }

        public function getTempnr($gather_type=1){
            $pagehtml= curl_file_get_contents3($this->url);
            //echo "\r\n获取内容1:".js();
            //echo "\r\n>>>".preg_match("/404\sNot\sFoun|moved</Uisx",$pagehtml);
            if($pagehtml==""||preg_match("/html/Uisx",$pagehtml)!=1||preg_match("/404\sNot\sFoun|moved</Uisx",$pagehtml)){
                require_once APP_PATH.'/collect/lib/org/page.class.php';
                $rs=getre(host($this->url),'nr');
                $p=new Page($this->url,$rs['utf8'],$rs['coockie'],$rs['haveReferer']);
                $pagehtml= $p->html;
                //echo "\r\n获取内容2:".js();
                if(preg_match("/^Location\:(.*)$/Uixm",$pagehtml,$nn)){
                    $url=trim($nn[1]);
                    preg_match("/set\-cookie\:(.*)$/Uixm",$pagehtml,$nn);
                    $coockie.=trim($nn[1]);
                    $p=new Page($url,0,$coockie,$rs['haveReferer']);
                    $pagehtml= $p->html;
                }
            }    
            $pagehtml = preg_replace("/　/",'',$pagehtml);  
            if(preg_match('@<meta.+charset=([\w\-]+)[^>]*>@i',$pagehtml,$matches)){
                $charset = trim($matches[1]);
            }else{
                $charset =is_utf8($pagehtml)?"utf-8":"gbk";
            }
            $pagehtml = strtolower($charset)!='utf-8'?iconv($charset, 'utf-8//IGNORE',$pagehtml):$pagehtml;
            return $pagehtml;
        }

        public function getbt(){
            $rs=$this->rs;
            $tempnr=$this->ytempnr;
            if($rs['titlere']!=""){            
                $dd=preg_split("/\|\|\||$/m",$rs['titlere']);
                foreach($dd as $onedd){               
                    if(trim($onedd)==""||trim($onedd)=="@@") continue;
                    $mm=preg_split("/@@/",$onedd);
                    if(preg_match("/\(.*\)/Uisx",$mm[0])){
                        $mm[0]=trim($mm[0]);
                        preg_match_all("/".trim($mm[0])."/Uisx",$tempnr,$nn);
                        if(trim($subject)=="") $subject=$nn[1][0];
                    }
                }            
            }

            if($subject==""){
                preg_match_all("/<title>(.*)<\/title>/Uisx",$tempnr,$nn);
                $subject=trim($nn[1][0]);  
            }

            if($rs['titlere']!=""){
                $dd=preg_split("/\|\|\||$/m",$rs['titlere']);
                for($i=0;$i<count($dd);$i++){
                    if(trim($dd[$i])==""||trim($dd[$i])=="@@"||preg_match("/(?<!\\\)\(/Uisx",$mm[0])) continue;
                    $mm=preg_split("/@@/",$dd[$i]);
                    $subject=preg_replace("/".trim($mm[0])."/Uisx",$mm[1],$subject);
                }
            }
            $subject=strip_jscss($subject);
            $subject=preg_replace("/\"/","\\\"",strip_tags($subject,"<img><p><br><td><table><tr><ul><li><span><script>"));
            $subject=preg_replace("/(\r|\n)+|$/m","",trim($subject));
            $subject=preg_replace("/\&nbsp\;|\s+?/Uisx"," ",$subject);
            $subject=preg_replace("/(_|\-|\-|\—).*$/Uisx","",$subject);
            $subject=preg_replace("/(_|\-|\-|\||\s|\—).*(网|社区|论坛).*$/Uisx","",$subject);
            return $subject;
        }



        public function getbbs(){
            $tempnr=$this->nr;
            if(preg_match("/discuz/Uisx",$tempnr)){
                $tempnr=preg_replace("/<div[^<>]+class=\"a_pr\"[^<>]*>.*<\/div>/Uisx","",$tempnr);
                preg_match_all("/<div\s*class=\"authi\"[^<>]*>.*<a[^<>]*uid=[^<>]*>([^<>]*)<\/a>.*<td\s*class=\"t_f\"\s*id=\"postmessage_[0-9]+\">(.*)<\/td><\/tr><\/table>/Uisx",$tempnr,$nn);
                $userid=$nn[1][0];
                preg_match_all("/<div\s*class=\"authi\"[^<>]*>.*<a[^<>]*uid=[^<>]*>{$userid}<\/a>.*<td\s*class=\"t_f\"\s*id=\"postmessage_[0-9]+\">(.*)<\/td><\/tr><\/table>/Uisx",$tempnr,$nn);
                for($i=0;$i<count($nn[1]);$i++){
                    $textarea.=$nn[1][$i]."\r\n";
                    break;
                }



                if(trim($textarea)==""){
                    preg_match_all("/<td\s*class=\"t_f\"\s*id=\"postmessage_[0-9]+\">(.*)<\/td><\/tr><\/table>/Uisx",$tempnr,$nn);
                    for($i=0;$i<count($nn[1]);$i++){
                        $textarea.=$nn[1][$i]."\r\n";
                        break;
                    }            
                }

                if(trim($textarea)==""){
                    preg_match_all("/<div\s*class=\"minicorner\"><\/div>(.*)<a\sid=\"flowers\"/Uisx",$tempnr,$nn);
                    for($i=0;$i<count($nn[1]);$i++){
                        $textarea.=$nn[1][$i]."\r\n";
                        break;
                    }            
                }
            }

            if(preg_match("/tianya/Uisx",$tempnr)){
                preg_match_all("/<div[^<>]*class=\"post\"[^<>]*>(.*)<\/div>/Uisx",$tempnr,$nn);
                for($i=0;$i<count($nn[1]);$i++){
                    $textarea.=$nn[1][$i]."\r\n";
                    break;
                }
            }





            $rs=getre(host($this->url),'bbs');
            if($rs[re]!=""){
                $cc=explode("|||",$rs[re]);
                for($i=0;$i<count($cc);$i++){
                    if(trim($cc[$i])=="") continue;
                    if(!preg_match("/\&\&\&/Uisx",$cc[$i])){
                        if(preg_match("/\:y(?=$|\:)/Uisx",trim($cc[$i]))){
                            $cc[$i]=preg_replace("/\:y(?=$|\:)/","",$cc[$i]);
                            $tempnr=$this->ytempnr;
                        }else{
                            $tempnr=$this->nr;
                        }

                        if(preg_match("/\:nn([0-9]+)(?=$|\:)/Uisx",trim($cc[$i]),$mm4)){
                            $cc[$i]=preg_replace("/\:nn[0-9]+(?=$|\:)/Uisx","",trim($cc[$i]));
                            preg_match_all("/".trim($cc[$i])."/Uisx",$tempnr,${"nn".$mm4[1]});
                        }else{
                            if(trim($textarea)==""){
                                preg_match_all("/".trim($cc[$i])."/Uisx",$tempnr,$nn);
                                $textarea=trim($nn[1][0]);
                                if($this->bug==2){
                                    //echo "use rs[id]:".$rs[id];
                                    //echo "use re:".$cc[$i]."\r\n-----------------\r\n".$textarea."\r\n----------\r\n";
                                }
                            }
                        }
                    }else{
                        $textarea="";
                    }
                }
            }


            $textarea=strip_jscss($textarea);

            $textarea=preg_replace("/\"/","\\\"",strip_tags($textarea,"<img><p><br><td><table><tr><ul><li><span><script>"));
            //$textarea=preg_replace("/(\r|\n)+|$/m","\\r\\n",trim($textarea));


            preg_match_all("/<img([^<>]*)>/Uisx",$textarea,$nn00);
            for($i=0;$i<count($nn00[1]);$i++){
                preg_match_all("/file=\\\?\"([^<>]*)\\\??\"/Uisx",$nn00[0][$i],$nnn3);$src=$nnn3[1][0];


                if($src==""){
                    preg_match_all("/original\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx",$nn00[0][$i],$nnn2);$src=$nnn2[1][0];
                }                     


                if($src==""){
                    preg_match_all("/src=\\\?\"([^<>]*)\\\??\"/Uisx",$nn00[0][$i],$nnn2);$src=$nnn2[1][0];
                }

                if($rs['loadimg']==1){
                    $textarea=str_replace($nn00[0][$i],"[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=".surlencode(quanurl($src,$this->url))."[/img]",$textarea);
                }else{
                    $textarea=str_replace($nn00[0][$i],"[img]".quanurl($src,$this->url)."[/img]",$textarea);
                }
            }

            $textarea=preg_replace("/本帖.*[0-9\-\s\:]编辑/Uisx","",$textarea);
            $textarea=preg_replace("/<span[^<>]*style=\\\?\"display\:none\\\?\"[^<>]*>.*<\/span>/Uisx","",trim($textarea));
            $textarea=preg_replace("/<span[^<>]*>|<\/\s*span>/Uisx","",$textarea);
            $textarea=preg_replace("/\(微博\)/m","",trim($textarea));
            $textarea=preg_replace("/([0-9]+\-[0-9]+\-[0-9]+\s[0-9]+\:[0-9]+\:[0-9]+\s上传|下载附件).*$/m","",$textarea);

            if($rs['delete']!=""){
                $dd=preg_split("/\|\|\||$/m",$rs['delete']);
                for($i=0;$i<count($dd);$i++){
                    if(trim($dd[$i])==""||trim($dd[$i])=="@@") continue;
                    $mm=preg_split("/@@/",$dd[$i]);
                    $textarea=preg_replace("/".trim(u($mm[0]))."/Uisx",$mm[1],$textarea);
                }
            }

            if($rs['exec']!=""){
                if($rs[re]!=""){
                    $ddd=explode("&&&",$rs[re]);
                    if(count($ddd)>1){
                        $tempnr=$this->nr;
                        for($d=0;$d<count($ddd)-1;$d++){
                            preg_match_all("/".trim($ddd[$d])."/Uisx",$tempnr,$nn);
                            $tempnr=$nn[1][0];
                        }
                        preg_match_all("/".$ddd[count($ddd)-1]."/Uisx",$tempnr,$nn);
                    }else{
                        preg_match_all("/".$rs[re]."/Uisx",$tempnr,$nn);
                    }
                }
                eval($rs['exec']);
            }
            $textarea=htmltotxt($textarea, 0, "", "", false,$this->keeptable);
            $textarea=droppagetablediv($textarea);//删除第页行
            $textarea=changeloadimg($textarea,$rs);
            return $textarea;
        }

        public function getflv(){
            switch(host($this->url)){
                case "tudou.com":
                    preg_match_all("/tudou\.com\/(.*)\//Uisx",$this->url,$nn);
                    switch($nn[1][0]){
                        case "albumplay":
                            $a="a";break;
                        case "programs":
                            $a="v";break;
                        default:
                            $a="l";
                    }
                    preg_match_all("/(?:l|i|a)id\s*=\s*([0-9]*)/isx",$this->nr,$nn);$lid=$nn[1][0];
                    preg_match_all("/\,(?:l|i|a)code\s*=\s*'([^']*)'/Uisx",$this->nr,$nn);$lcode=$nn[1][0];
                    preg_match_all("/\,adesc\:\"([^<>]*)\"/Uisx",$this->nr,$nn);$jj=$this->jj=clmh($nn[1][0]);
                    preg_match_all("/\,pic\:\"([^<>]*)\"/Uisx",$this->nr,$nn);$pic=$this->pic=clmh($nn[1][0]);
                    if($pic!="") $picimg="<img src=\"{$pic}\">";
                    $textarea="[media=swf,500,375]http://www.tudou.com/{$a}/{$lcode}/&resourceId=0_05_05_99&iid={$lid}&bid=05/v.swf[/media]";
                    $textarea=clmh($textarea);
                    break;
                case "youku.com":
                    preg_match_all("/id_(.*)\.html/Uisx",$this->url,$nn);$id=$nn[1][0];
                    preg_match_all("/\,(?:l|i|a)code\s*=\s*'([^']*)'/Uisx",$this->nr,$nn);$lcode=$nn[1][0];
                    preg_match_all("/\,adesc\:\"([^<>]*)\"/Uisx",$this->nr,$nn);$jj=$this->jj=clmh($nn[1][0]);
                    preg_match_all("/<li\s*class=\"v_thumb\"><img\s*src=\"([^<>]*)\"/Uisx",$this->nr,$nn);$pic=$this->pic=clmh($nn[1][0]);
                    if($pic!="") $picimg="<img src=\"{$pic}\">";
                    $textarea="[media=swf,500,375]http://player.youku.com/player.php/sid/{$id}/v.swf[/media]";
                    $textarea=clmh($textarea);
                    break;
            }
            $textarea=$this->swfstr.$textarea;
            return $textarea;
        }

        public function getnr(){
            global $textarea;
            $tempnr=$this->nr;
            $inifile=$_SERVER['DOCUMENT_ROOT']."/collect/lib/CollcetLib/".host($this->url).".inc.php";
            //echo $inifile;
            if(is_file($inifile)){
                include($inifile);
            }

            if($textarea==""){
                $textarea="";//clear
                $rs=$this->rs;
                if($rs[re]!=""){
                    $cc=preg_split("/\|\|\||$/m",$rs['re']);
                    //if($this->bug==1) echo $this->nr;
                    for($i=0;$i<count($cc);$i++){
                        if(trim($cc[$i])=="") continue;
                        if(preg_match("/\:y(?=$|\:)/Uisx",trim($cc[$i]))){
                            $cc[$i]=preg_replace("/\:y(?=$|\:)/","",$cc[$i]);
                            $tempnr=$this->ytempnr;
                        }else{
                            $tempnr=$this->nr;
                        }
                        if(!preg_match("/\&\&\&/Uisx",$cc[$i])){
                            if($this->bug==2){$fn=fopen("d:/temp.txt","w");fwrite($fn,$this->url."\r\n".$tempnr);fclose($fn);}
                            if(preg_match("/\:nn([0-9]+)(?=$|\:)/Uisx",trim($cc[$i]),$mm4)){
                                $cc[$i]=preg_replace("/\:nn[0-9]+(?=$|\:)/Uisx","",trim($cc[$i]));
                                preg_match_all("/".trim($cc[$i])."/Uisx",$tempnr,${"nn".$mm4[1]});
                                if($this->bug==5){
                                    echo "nn".$mm4[1];
                                    print_r(${"nn".$mm4[1]});
                                }
                            }else{
                                if(trim($textarea)==""){
                                    $cc[$i]=trim($cc[$i]);
                                    //$cc[$i]=g($cc[$i]);
                                    preg_match_all("/".trim($cc[$i])."/Uisx",$tempnr,$nn);
                                    $textarea=trim($nn[1][0]);
                                    if($this->bug==2){                                                                            //XXXXXXXXXXXXXXXXXX
                                        echo $cc[$i]."\r\nbegin re-----------------\r\n".substr($textarea,0,500)."\r\n----------end re\r\n";
                                    }
                                }
                            }
                        }else{
                            $ddd=explode("&&&",$cc[$i]);
                            $tempnr=$this->ytempnr;

                            for($d=0;$d<count($ddd)-1;$d++){
                                preg_match_all("/".trim($ddd[$d])."/Uisx",$tempnr,$nn);
                                if(trim($nn[1][0])==""){
                                    break;
                                }else{
                                    $tempnr=$nn[1][0];
                                }
                            }

                            if(preg_match("/\:nn([0-9]+)(?=\:|$)/Uisx",trim($ddd[count($ddd)-1]),$mm3)){
                                $ddd[count($ddd)-1]=preg_replace("/\:nn[0-9]+(?=\:|$)/Uisx","",trim($ddd[count($ddd)-1]));
                                preg_match_all("/".trim($ddd[count($ddd)-1])."/Uisx",$tempnr,${"nn".$mm3[1]});
                                if(trim(${"nn".$mm3[1]."[1][0]"})=="")     break;    
                                $textarea=$tempnr=${"nn".$mm3[1]."[1][0]"};
                                $params=array("nn22"=>$nn22,"nn11"=>$nn11,"nn99"=>$nn99);
                                $textarea=evalpublic($tempnr,$this->url,$params,$rs,$this->bug);
                            }else{
                                $textarea=${"nn".$mm3[1]."[1][0]"};
                            }

                            if($this->bug==2){                                                                            //XXXXXXXXXXXXXXXXXX
                                echo $cc[$i]."\r\nbegin re-----------------\r\n".substr($textarea,0,500)."\r\n----------end re\r\n";
                                //exit;
                            }
                        }
                        if(trim($textarea)){
                            break;
                        }
                    }
                }

                if(trim($textarea)==""){
                    $tempnr=$this->tempnr;
                    if(preg_match("/discuz/Uisx",$tempnr)&&(!istextarea(strip_tags($textarea,"<img>"))||$textarea=="")){
                        $tempnr=preg_replace("/<div[^<>]+class=\"a_pr\"[^<>]*>.*<\/div>/Uisx","",$tempnr);
                        if(!istextarea(strip_tags($textarea,"<img>"))||$textarea==""){
                            if($this->bug==2){$fn=fopen("d:/tempb.txt","w");fwrite($fn,$this->url."\r\n".$tempnr);fclose($fn);}
                            preg_match_all("/<td\s*[^<>]+id=\"postmessage_[0-9]+\"[^<>]*>(.*)(?=<td\s*[^<>]+id=\"postmessage_[0-9]+\"|相关帖子|$)/Uisx",$tempnr,$nn);
                            for($i=0;$i<count($nn[1]);$i++){
                                if($this->bug==2) echo "公共正则5.4";
                                $textarea.=$nn[1][$i]."\r\n";
                                break;
                            }            
                        }


                        if(!istextarea(strip_tags($textarea,"<img>"))||$textarea==""){
                            if($this->bug==2) echo "公共正则5";
                            preg_match_all("/<div\s*class=\"authi\"[^<>]*>.*<a[^<>]*uid=[^<>]*>([^<>]*)<\/a>.*<td\s*class=\"t_f\"\s*id=\"postmessage_[0-9]+\">(.*)<\/td><\/tr><\/table>/Uisx",$tempnr,$nn);
                            $userid=$nn[1][0];
                            preg_match_all("/<div\s*class=\"authi\"[^<>]*>.*<a[^<>]*uid=[^<>]*>{$userid}<\/a>.*<td\s*class=\"t_f\"\s*id=\"postmessage_[0-9]+\">(.*)<\/td><\/tr><\/table>/Uisx",$tempnr,$nn);
                            for($i=0;$i<count($nn[1]);$i++){
                                if($this->bug==2) echo "公共正则5.2";
                                $textarea.=$nn[1][$i]."\r\n";
                                break;
                            }
                        }


                        if(!istextarea(strip_tags($textarea,"<img>"))||$textarea==""){
                            preg_match_all("/<div\s*class=\"minicorner\"><\/div>(.*)<a\sid=\"flowers\"/Uisx",$tempnr,$nn);
                            for($i=0;$i<count($nn[1]);$i++){
                                if($this->bug==2) echo "公共正则5.3";
                                $textarea.=$nn[1][$i]."\r\n";
                                break;
                            }            
                        }
                    }

                    if(preg_match("/tianya/Uisx",$tempnr)&&(!istextarea(strip_tags($textarea,"<img>"))||$textarea=="")){
                        //preg_match_all("/<div[^<>]*class=\"post\"[^<>]*>(.*)<\/div>/Uisx",$tempnr,$nn);
                        //$userid=$nn[1][0];
                        preg_match_all("/<div[^<>]*class=\"post\"[^<>]*>(.*)<\/div>/Uisx",$tempnr,$nn);
                        for($i=0;$i<count($nn[1]);$i++){
                            if($this->bug==2) echo "公共正则6";
                            $textarea.=$nn[1][$i]."\r\n";
                            break;
                        }
                    }

                    if(!istextarea(strip_tags($textarea,"<img>"))||$textarea==""){
                        if(preg_match_all("/<\!\-\-enpcontent\-\-><\!\-\-enpcontent\-\->(.*)<\!\-\-\/enpcontent\-\->\s*<\/td>/Uisx",$this->yuannr,$nn00)){
                            if($this->bug==2) echo "公共正则1";
                            $textarea=$nn00[1][0];
                        }

                        if(preg_match_all("/<\!\-\-function\s+content\(\)\s+parse\s+begin\-\->(.*)<\!\-\-function\:\s+content\(\)\s+parse\s+end[^<>]*\-\->/Uisx",$this->yuannr,$nn00)){
                            if($this->bug==2) echo "公共正则2";
                            $textarea=$nn00[1][0];
                        }


                        if(preg_match_all("/\/enpproperty\-\-><\!\-\-enpcontent\-\->(.*)<span[^<>]+class\s*=\s*\"pageNum\"[^<>]*>/Uisx",$this->yuannr,$nn00)){
                            if($this->bug==2) echo "公共正则3";
                            $textarea=$nn00[1][0];
                        }


                        if(preg_match_all("/<div\s+id=\"contentarea\">(.*)<\/div>/Uisx",$this->yuannr,$nn00)){
                            if($this->bug==2) echo "公共正则4";
                            $textarea=$nn00[1][0];
                        }

                        if(preg_match_all("/<div[^<>]*(?:id|class)=\"(?:content|neirong|zhenwen|nr|zwnr|text|novel_content)\"[^<>]*>(((?<!<\/div).)*)<\/div>/Uisx",$this->yuannr,$nn00)){
                            if($this->bug==2) echo "公共正则5";
                            $textarea=$nn00[1][0];
                        }

                        if(preg_match_all("/<div[^<>]*(?:id|class)=\"(?:content|neirong|zhenwen|nr|zwnr|text|novel_content)\"[^<>]*>(((?<!<\/div).)*)<\/div>/Uisx",$this->tempnr,$nn00)){
                            if($this->bug==2) echo "公共正则6";
                            $textarea=$nn00[1][0];
                        }
                    }




                    //if($this->bug==1){echo ">>>".strlen(strip_tags($textarea));}   //XXXXXXXXXXXXXXXXXX
                    //$tempnr=(isutf8(tempnr))?$tempnr:u($tempnr);
                    //if($this->bug==2){
                    //$fn=fopen("d:/1.txt","w");fwrite($fn,$tempnr);fclose($fn);
                    //}

                    $m=0;
                    if(!istextarea(strip_tags($textarea,"<img>"))||$textarea==""){
                        $tempnr=$this->tempnr;
                        //echo $tempnr;
                        do{
                            preg_match_all("/<div[^<>]*>((?:.(?!\<div))*)<\/div>/Uisx",$tempnr,$nnn);
                            //print_r($nnn[1]);
                            for($i=0;$i<count($nnn[1]);$i++){
                                //$nnn[1][$i]=(isutf8(tempnr))?$nnn[1][$i]:u($nnn[1][$i]);
                                preg_match_all("/(。|，|<img[^<>]*width=\"[4-9][5-9][0-9]\"|<P\s*align=center>\s*<img)/Uixs",$nnn[1][$i],$mm);
                                if(count($mm[1])>0){
                                    $cl=0;
                                    $havejuhao=0;
                                    for($j=0;$j<count($mm[1]);$j++){
                                        switch(trim(substr(strtolower($mm[1][$j]),0,4))){
                                            case "。":
                                            case g("。"):
                                            case "，":
                                            case g("，"):
                                                $cl=$cl+2;
                                                $havejuhao++;
                                                break;
                                            case "<img":
                                            case "<p a":
                                                $cl=$cl+3;break;
                                        }

                                    }
                                    if($havejuhao>0){
                                        $sl[]=$cl;
                                        $mbnr[]=$nnn[1][$i];
                                    }
                                    //echo "<br>\r\n<<<--------------------- {$nnn[1][$i]}---------------------->>>\r\n<br>";
                                    if($this->bug==2) echo "\r\n<br>-------------div_{$cl}_{i:$i}----------------\r\n<br>".$nnn[1][$i];
                                }else{
                                    //echo "WWW:".$nnn[1][$i]."\r\n";
                                }
                                $tempnr=str_replace($nnn[0][$i],"",$tempnr);
                            }
                            //echo $m."-".count($nnn[1])."\r\n";exit;
                            $m++;
                        }while(count($nnn[1])>1&&$m<20);
                        $textarea=$mbnr[my_array_max($sl)];
                        if($this->bug==3) echo "----".$textarea;
                        if($this->bug==2){
                            //print_r($sl);
                            //echo $sl[my_array_max($sl)];
                            //echo "---".my_array_max($sl)."\r\n";
                        }



                        $tempnr=$this->nr;
                        if(preg_match("/<table/Uisx",$tempnr)){
                            preg_match_all("/<td[^<>]*>((?:.(?!\<td))*)<\/td>/Uisx",$this->nr,$nnn2);
                            for($i=0;$i<count($nnn2[1]);$i++){
                                if(preg_match_all("/(。|，|<img[^<>]*width=\"[4-9][5-9][0-9]\")/Uisx",$nnn2[1][$i],$mm)){

                                    $c2=0;
                                    for($j=0;$j<count($mm[1]);$j++){
                                        switch(trim(substr(strtolower($mm[1][$j]),0,4))){
                                            case "。":
                                            case "，":
                                            case g("，"):
                                            case g("。"):
                                                $c2=$c2+2;break;
                                            case "<img":
                                                $c2=$c2+0;break;
                                        }
                                    }                        
                                    $sl2[]=$c2;
                                    $mbnr2[]=$nnn2[1][$i];
                                    if($this->bug==2) echo "\r\n-------------td[".$c2."]----------------\r\n".$nnn2[1][$i];
                                }
                            }
                            if($sl2[my_array_max($sl2)]>=$sl[my_array_max($sl)]) $textarea=$mbnr2[my_array_max($sl2)];
                        }
                    }
                }//

                if($this->bug==2){echo "\r\n分西后---------------->>>".$textarea."\r\nEnd 分西后-------------\r\n";}
                $textarea=strip_jscss($textarea);

                $textarea=preg_replace("/(<img[^<>]*)\s+?\/>/Uisx","\\1>",$textarea);



                //if($this->bug){echo count($nn2[1]);exit;}

                if($rs[re]!=""){
                    $dd=preg_split("/\|\|\||$/m",$rs['re']);
                    for($j=0;$j<count($dd);$j++){
                        if(trim($dd[$j])=="") continue;
                        $ddd=explode("&&&",$dd[$j]);
                        if(count($ddd)>1){
                            $tempnr=$this->nr;

                            for($d=0;$d<count($ddd)-1;$d++){

                                preg_match_all("/".trim($ddd[$d])."/Uisx",$tempnr,$nn);
                                $tempnr=$nn[1][0];
                            }
                            if(preg_match("/\:nn([0-9]+)(?=\:|$)/Uisx",trim($ddd[count($ddd)-1]),$mm3)){

                                $ddd[count($ddd)-1]=preg_replace("/\:nn[0-9]+(?=\:|$)/Uisx","",trim($ddd[count($ddd)-1]));
                                preg_match_all("/".trim($ddd[count($ddd)-1])."/Uisx",$tempnr,${"nn".$mm3[1]});
                            }                  
                            if($this->bug==9){
                                //print_r($nn2);
                                //echo "nn".$mm3[1]."\r\n";
                                //print_r(${"nn".$mm3[1]});
                            }
                        }
                    }
                }


                if($rs['exec']!=""&&!$this->secexe){
                    //if($this->bug==2) echo "\r\n\r\n\r\npage:>>>>>>>>>>>>>>>>>>>$this->url";
                    eval($rs['exec']);
                }



                $params=array("nn22"=>$nn22,"nn11"=>$nn11,"nn99"=>$nn99);
                $textarea=evalpublic($textarea,$this->url,$params,$rs,$this->bug);

                if($this->bug==2){echo "\r\nEXEC后---------------->>>".$textarea."\r\nEnd EXEC后-------------\r\n";}

                $textarea=preg_replace("/本帖.*[0-9\-\s\:]编辑|<\/img>|<br\s*\/>|\&lt\;br\s*\/\&gt\;/Uisx","",$textarea);
                //$textarea=preg_replace("/(本帖子中包含更多资源|本主题由|帖子评分).*(\[查看记录\]|$)/Uisx","",$textarea);
                $textarea=preg_replace("/分享到.*$/Uisx","",$textarea);
                $textarea=preg_replace("/<span[^<>]*style=\\\?\"display\:none\\\?\"[^<>]*>.*<\/span>/Uisx","",trim($textarea));
                $textarea=preg_replace("/<span[^<>]*>|<\/\s*span>/Uisx","",$textarea);
                $textarea=preg_replace("/\(微博\)/m","",trim($textarea));
                $textarea=preg_replace("/([0-9]+\-[0-9]+\-[0-9]+\s[0-9]+\:[0-9]+\:[0-9]+\s上传|下载附件).*$/m","",$textarea);
                $textarea=preg_replace("/<(\/?)(b|strong)\s*\/?>/Uisx","[\\1b]",$textarea);
                $textarea=preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx","",$textarea);
                $textarea=preg_replace("/^.*\/enpproperty\-\-\>/Uisx","",trim($textarea));
                if($this->bug==2){echo "\r\nPreg_replace后---------------->>>".$textarea."\r\nEnd Preg_replace后-------------\r\n";}
                $textarea=htmltotxt($textarea,$rs['clhc'],$this->url);
                if($this->bug==2){echo "\r\nHmltotxt后---------------->>>".$textarea."\r\nEnd Hmltotxt后-------------\r\n";}

                //yzs 删除分页的表格或div
                $textarea=droppagetablediv($textarea,$this->nextpagere,$this->bug);//删除第页行

                //yzs 删除开始,处理删除deletere
                if($rs['delete']!=""){
                    $dd=preg_split("/\|\|\||$/m",$rs['delete']);
                    for($i=0;$i<count($dd);$i++){
                        if(trim($dd[$i])=="") continue;
                        $mm=preg_split("/@@/",$dd[$i]);
                        if(preg_match("/\:y(?=\:|$)/Uisx",trim($mm[0]))){
                            $mm[0]=preg_replace("/\:y(?=\:|$)/","",trim($mm[0]));
                        }elseif(preg_match("/\:g(?=\:|$)/Uisx",trim($mm[0]))){
                            $mm[0]=preg_replace("/\:g(?=\:|$)/Uisx","",trim($mm[0]));
                        }
                        if($this->bug==4) echo "\r\nDelete re:".$rs['delete']."\r\n".$mm[0]."-----------------\r\n";
                        $textarea=preg_replace("/".trim($mm[0])."/Uisx",$mm[1],$textarea);
                    }
                }

                if($this->bug==2){echo "\r\nDelete后---------------->>>".$textarea."\r\nEnd Delete后-------------\r\n";}


            }

            //if(preg_match("/信息/Uixs",$this->title)) echo 9999;
            $textarea=changeloadimg($textarea,$this->rs);
            $textarea=$this->swfstr.$textarea;
            $textarea=preg_replace("/(\[align=center\]\s*\[\/align\](\s|　)*){2,}/isx","\r\n　　",$textarea); 
            $textarea=preg_replace("/\[media[^<>\[\]]*\][^<>\[\]]*Array\[\/media\]/Uisx","",$textarea);
            return $textarea;
        }



        //静态方法
        static public function usefunc($unitid,$unittype_id,$unitname){
            return $result;
        }

        function redo($url){
            //if(!$this->secexe){
            $news2=new Zqnews($url);
            $this->secexe=1;
            return $news2->getnr();
            //}else{
            //return "";
            //}
        }

        public function zq($re){
            global $tempnr;
            preg_match_all("/".trim($re)."/Uisx",$tempnr,$nn);
            $return=$nn[1][0];
            return $return;
        }

        public function getrs(){
            $rs=getre(host($this->url),'nr');
            //echo host($this->url);exit;
            $this->rs=$rs;
            //echo $rs[id];
            if(trim($rs[nextpage])!=""){
                $cc=explode("|||",$rs[nextpage]);
                for($i=0;$i<count($cc);$i++){
                    if(trim($cc[$i])!=""){
                        if(!preg_match("/(?<!\\\)\(.*\)/Uisx",$cc[$i])){
                            $nextpage="|".trim($cc[$i]);
                        }else{
                            $nextpagerem[]=trim($cc[$i]);
                        }
                    }
                }
                $this->nextpagere=$nextpage;
                $this->nextpagerem=$nextpagerem;
            }
            return $rs;
        }

    }
?>